<?
include('../controller/handler.php');
include('../controller/philomousia.php');

include('../module/var.inc.php');

session_start();


$hd = new Handler();
$base_url = $hd->getBaseURL();
if($_POST!=NULL && $hd->getPassword()==sha1($_SESSION['password'])) {
	$ph = new Philomousia();
	$hd->openDB();
	$ph->insertPerson($_POST['name'], $_POST['surname'], $_POST['description'], 
		$_POST['mail'], $_POST['img'], $_POST['url'], $_POST['location'], $hd);
	$hd->closeDB();
	$feedback = "Persona aggiunta con successo. La sezione <a href=\"".$base_url."people\">Gruppo</a> è stata aggiornata.";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" lang="it">
<head>
	<? include('../module/head.inc.php'); ?>
	<meta name="robots" content="noindex, nofollow"/>
	<script src="<?echo $base_url;?>js/editor.js" type="text/javascript" charset="utf-8"></script>
</head>

<body>
<div id="content">
<?include('../module/header.inc.php');?>

<?if($hd->getPassword()==sha1($_SESSION['password'])) {?>

<div id="panel_form" class="form">
	<div class="upper_bar_main"><div class="upper_bar_round"></div></div>
	<div class="body_main_left">
	<div class="body_main_right">
	<div class="body_main">
	<form action="person" method="post" accept-charset="utf-8" onsubmit="return peopleForm(this);;">
		<h2>Aggiungi persona</h2>
		<table border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td width="380px">
					<input type="text" class="text" name="name" value="" /> Nome<br />
					<input type="text" class="text" name="surname" value="" /> Cognome<br />
					<input type="text" class="text" name="img" value="" id="auto_img" /> Immagine*<br />
					<div id="auto_img_choices"></div>
					<input type="text" class="text" name="location" value="" /> Luogo*<br />
					<input type="text" class="text" name="mail" value="" /> e-mail*<br />
					<input type="text" class="text" name="url" value="" /> Sito personale*
				</td><td></td></tr>
			<tr>
				<td><textarea id="txt" name="description" rows="10" cols="45"></textarea></td>
				<td>
					<?include("../module/editor.inc.php");?>
				</td>
			</tr>
		</table>
		<p><input type="button" value="Anteprima &rarr;" onclick="showPreview('txt', '<?echo $base_url?>')" />
			<input type="submit" value="Aggiungi &rarr;" /></p>
	</form>
	<?if($feedback) {?><p id="feedback" class="highline"><?echo $feedback;?></p> <?}?>
	<p class="small admin_action"><a href="<?echo $base_url;?>panel">&larr; Pannello di amministrazione</a></p>
	</div></div></div>
	<div class="lower_bar_main"><div class="lower_bar_round"></div></div>
</div>

<script type="text/javascript" charset="utf-8">
//<![CDATA[
	new Ajax.Autocompleter("auto_img", "auto_img_choices", "<?echo $hd->getBaseURL();?>img", {
		paramName:"img", 
		minChars:1,
		updateElement:function(elem) {
			$('auto_img').value = elem.id;
		}
	});
//]]>
</script>

<?include('../module/preview.inc.php');?>
<?include('../module/uploaded.img.inc.php');?>

<?}?>

<? include('../module/footer.inc.php'); ?>
</div>
</body>
</html>
